package com.example.demo.day0302;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class DemoSerialize {
    public static void main(String[] args) {
        try {
            DemoSerialize.testSerialize();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    public static void  testSerialize() throws Exception {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt8.txt"));
        //定义对象的输出流，把对象的序列化之后的流放到指定的文件中

        Man m =new Man();
        m.name = "Tom";
        m.age = 11;

        out.writeObject(m);//将p存至内存
        out.flush();//刷到硬盘上

        out.close();//关闭流

    }
}
